<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('设备货位库房信息')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <h4 class="form-header h4">设备货位区域信息</h4>
            <div class="col-sm-offset-5 col-sm-10">
                <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存
                </button>&nbsp;
                <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
                </button>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-danger multiple disabled" onclick="remodifyHandler()">
                    <i class="fa fa-remove"></i> 移除库区
                </a>
                <!--		            <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="system:device:import">-->
                <!--			            <i class="fa fa-upload"></i> 导入-->
                <!--			        </a>-->
                <!--		            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:device:export">-->
                <!--			            <i class="fa fa-download"></i> 导出-->
                <!--			        </a>-->
            </div>
            <div id="div" class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('device:cargoSpace:edit')}]];
    var removeFlag = [[${@permission.hasPermi('device:cargoSpace:remove')}]];
    var prefix = ctx + "device/basCargoSpace";

    //页面加载完成后执行
    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});
        // 回到顶部绑定
        if ($.fn.toTop !== undefined) {
            var opt = {
                win: $('.ui-layout-center'),
                doc: $('.ui-layout-center')
            };
            $('#scroll-up').toTop(opt);
        }
        queryUserList();
    });

    function queryUserList() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            height: $("#div").height()/1,
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            sortName: "cargo_space_id", //排序字段
            sortOrder: "desc",   //排序规则
            pagination: true,//显示分页
            modalName: "设备仓库",
            columns: [{
                checkbox: true
            },
                {
                    field: 'cargo_space_id',
                    title: '货位id '
                },
                {
                    field: 'warehouse_id',
                    title: '仓库ID',
                    sortable: true
                },
                {
                    field: 'roadway_id',
                    title: '巷道ID'
                },
                {
                    field: 'cargo_area_id',
                    title: '货区ID'
                },
                {
                    field: 'the_type',
                    title: '货位类型',
                },
                {
                    field: 'the_type_name',
                    title: '货位类型名称',
                },
                {
                    field: 'cargo_space_name',
                    title: '货位名称',
                },
                {
                    field: 'the_platoon',
                    title: '排',
                },
                {
                    field: 'the_column',
                    title: "列",
                },
                {
                    field: 'the_floor',
                    title: '层',
                },
                {
                    field: 'tray_code',
                    title: '托盘条码',
                },
                {
                    field: 'cargo_hight',
                    title: '货位高度',
                },
                {
                    field: 'iss_double',
                    title: '是否双伸',
                },
                {
                    field: 'group_coding_no',
                    title: '双货位分组编码',
                },
                {
                    field: 'group_coding',
                    title: '双货位分组编码',
                },
                {
                    field: 'cargo_space_logo',
                    title: '双货位分组标识',
                },
                {
                    field: 'this_cargo_area',
                    title: '本仓库区域',
                },
                {
                    visible: editFlag == 'status' ? "1" : "2",
                    title: '货位状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="remodifyHandler(\'' + row.cargo_space_id + '\')"><i class="fa fa-remove"></i>移除库区</a> ');
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    }

    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function () {
        queryDeptTree();
    });

    /* 锁定状态显示 */
    function lockdeTools(row) {
        if (row.locked == "N") {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="disable(\'' + row.cargo_space_id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="enable(\'' + row.cargo_space_id + '\')"></i> ';
        }
    }

    /* 用户状态显示 */
    function statusTools(row) {
        if (row.status == "1") {
            return '<i>空货位</i> ';
        } else {
            return '<i>满货位</i> ';
        }
    }


    /* 设备仓库管理-锁定 */
    function disable(cargo_space_id) {
        $.modal.confirm("是否将货位锁定？", function () {
            $.operate.post(prefix + "/changeLocked", {"cargo_space_id": cargo_space_id, "locked": "Y"});
        })
    }

    /* 设备仓库管理解锁 */
    function enable(cargo_space_id) {
        $.modal.confirm("是否将货位解锁？", function () {
            $.operate.post(prefix + "/changeLocked", {"cargo_space_id": cargo_space_id, "locked": "N"});
        })
    }
    var prefixarea = ctx + "device/cargoArea";

    function  submitHandler(){
        var ids = new Array();
        var rows=$("#bootstrap-table").bootstrapTable('getSelections');
        for (var i = 0; i < rows.length; i++) {
            ids.push(rows[i].cargo_space_id)
        }
        var cargo_area_id= [[${cargo_area_id}]];
        var basAreaSpace = {};
        basAreaSpace["cargoAreaId"] = cargo_area_id;
        basAreaSpace["ids"] = ids;

        $.operate.modifysTab(prefixarea + "/modify",JSON.stringify(basAreaSpace));
    }
    function  remodifyHandler(){
        var ids = new Array();
        var rows=$("#bootstrap-table").bootstrapTable('getSelections');
        for (var i = 0; i < rows.length; i++) {
            ids.push(rows[i].cargo_space_id)
        }
        console.log(ids);
        $.operate.modifysTab(prefixarea + "/remodify",JSON.stringify(ids));
    }
    function remodifyHandler(id) {
        table.set();
        $.modal.confirm("确定移除该条" + table.options.modalName + "货位的库区信息吗？", function() {
            var ids = new Array();
            ids.push(id)
            $.operate.modifysTab(prefixarea + "/remodify",JSON.stringify(ids));
        });
    }
</script>
</body>
</html>